Component({
  properties: {
    activeIndex: {
      type: Number,
      value: 0
    }
  },
  data: {
    menus: [{
        name: '首页',
        url: '/pages/giftShop/home/index',
        icon_active: '/images/icon-home-active.png',
        icon_inactive: '/images/icon-home.png'
      },
      {
        name: '商品分类',
        url: '/pages/giftShop/goodsclassify/index',
        icon_active: '/images/icon-goods-classify-active.png',
        icon_inactive: '/images/icon-goods-classify.png'
      },
      {
        name: '购物车',
        url: '/pages/giftShop/shoppingCart/index',
        icon_active: '/images/icon-shoppingcart-active.png',
        icon_inactive: '/images/icon-shoppingcart.png'
      },
      {
        name: '会员中心',
        url: '/pages/giftShop/memberCenter/index',
        icon_active: '/images/icon-membercenter-active.png',
        icon_inactive: '/images/icon-membercenter.png'
      }
    ]
  },
  methods: {
    changeTab(e) {
      this.goPage(e.currentTarget.dataset.index)
      this.goMenu(e.currentTarget.dataset.index)
    },
    goPage(index) {
      let that = this;
      if (that.data.activeIndex !== index) {
        wx.reLaunch({
          url: this.data.menus[index].url
        })
      }
    },
    goMenu(index) {
      if (index == 0) {
        wx.reportAnalytics('gift_home')
      } else if (index == 1) {
        wx.reportAnalytics('gift_goodscategory')
      } else if (index == 2) {
        wx.reportAnalytics('gift_cart')
      } else if (index == 3) {
        wx.reportAnalytics('gift_member')
      }
    }
  }
})